<?php
session_start();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>欢迎登录</title>

<style type="text/css">
    .code
    {
            background:url(code_bg.jpg);
            font-family:Arial;
            font-style:italic;
             color:red;
             font-size:15px;
             border:0;
             padding:2px 3px;
             letter-spacing:3px;
             font-weight:bolder;             
             float:left;            
             cursor:pointer;
             width:55;
             height:30px;
             line-height:30px;
             text-align:center;
             vertical-align:middle;

    }
    a
    {
        text-decoration:none;
        font-size:12px;
        color:#288bc4;
        }
    a:hover
    {
       text-decoration:underline;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var code;
        function createCode() {
            code = "";
            var codeLength = 1; //验证码的长度
            var checkCode = document.getElementById("checkCode");
            var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
            'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符，当然也可以用中文的
            for (var i = 0; i < codeLength; i++) 
            {
                var charNum = Math.floor(Math.random() * 52);
                code += codeChars[charNum];
            }
            if (checkCode) 
            {
                checkCode.className = "code";
                checkCode.innerHTML = code;
            }
        }
        function validateCode() 
        {
            var inputCode = document.getElementById("inputCode").value;
            if (inputCode.length <= 0) 
            {
                alert("请输入验证码！");
				return false;
            }
            else if (inputCode.toUpperCase() != code.toUpperCase()) 
            {
                alert("验证码输入有误！");
                createCode();
				return false;
            }
            else 
            {
               //alert("验证码正确！");
				return true;
            }        
        }    
     </script>
</head>
<body bgcolor="#EAEAEC">
<table>
	<tr>
	<td>
	<img src="bg.png" >
	</td>
	<td>
	<?php
	require 'config.php';
	if(isset($_GET['sub']))
	{
		$user=$_GET['user'];
		$pwd=$_GET['pwd'];
		$sql="select *from user where user='$user' and pwd='$pwd'";
		$query=mysqli_query($conn,$sql);
		$rs=mysqli_fetch_assoc($query);
		$id=$rs['id'];
		$num=mysqli_num_rows($query);
		if($num)
		{
			$_SESSION['user']=$user;
			$_SESSION['pwd']=$pwd;
			$_SESSION['id']=$id;
			$sql="update user set times=times+1 where id=$id";
			$query=mysqli_query($conn,$sql);
			echo '<font face="楷体" size="6">登录成功,请稍等...</font><script>setTimeout(\'location.href="index.php"\',289118371)</script>';
		}
		else
			echo '<font face="楷体" size="6">您的账号或密码输入有误，请检查后再试</font><script>setTimeout(\'location.href="login.php"\',2900)</script>';
	}
	else
	{
	?>	
	<form>
	<table bgcolor="white" valign="center" width="400" style="border-radius:20px;">
		<tr>
		<th colspan="3"><br/></th>
		</tr>
		<tr>
			<th>&nbsp;用户名:</th>
			<td>
				<div class="list">
					<input TYPE="text" NAME="user" placeholder="请输入用户名" style="border-radius:5px; height:25px;" required ><br/>
			<th colspan="2" rowspan="2">
			&nbsp;
			</th>
				</div>
			</td>
		</tr>
		<tr>
			<th>&nbsp;密&nbsp;码:</th>
			<td><div class="list">
					<INPUT TYPE="password" NAME="pwd" placeholder="请输入密码" required style="border-radius:5px; height:25px;" >
				</div>
			</td>
		</tr>
		<tr>
		<script>
				window.onload=function()
				{
					createCode();//打开网页即显示验证码
				}
			</script>
			<th>&nbsp;验证码:</th>
			<td width="10%">
				<table>
					<tr>
						<td>
							<div class="code" id="checkCode" onclick="createCode()" >
						</td>
						<td>	
							<a  href="#" onclick="createCode()">换一张</a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<th>&nbsp;请输入:</th>
			<td><div class="list">
					<INPUT TYPE="text"placeholder="请输入验证码" required style="border-radius:5px; height:25px;" >
				</div>
			</td>
			<td rowspan="2"><input type="image" name="sub" width="60" value="登录" src="login.png"></td>
		</tr>
		<tr>
			<td colspan="2" align="center">
			
			</td>
		</tr>
		<tr>
		<th align="left" colspan="2"><font size="3">&nbsp;没账号？点我去<a href="register.php" style="color:red;font-size:16px">注册</a></td>
		</tr>
		<tr>
		<td colspan="2"><br/></td>
		</tr>
		<th align="right" colspan="3">忘记密码，点我去<a href="forget.php" style="color:red;font-size:16px">修改</a>&nbsp;&nbsp;</font></td>
		
		</tr>
	<?php }?>
	</table>
	<br><br>
	<table width="100%" style=" color:#fff;border-radius:10px;" bgcolor="#d7c2b5" align="center" border="0">
		<tr>
			<th>本页面仅周六 周天09:00-16:00开放注册</th>
		</tr>
</table>
	</form>
	</td>
	</tr>
</body>
</html>
